// Lang_21 [method references (static)].nova // The application class. class MethodReferencesStaticApp { // Application class's "main" function. public static void main( String[] args ) { // Declare a static method reference. String (static)( int, int ) methodRef = add; // Declare and initialize a generic method reference primitive. method m = methodRef; // Create a method reference object from the primitive. Method obj = new Method( methodRef ); // Output the method reference object. Stream.writeLine( obj.toString( ) ); // Output the method reference object using the static method. Stream.writeLine( Method.toString( methodRef ) ); // Call the static method reference. Stream.writeLine( methodRef( 5, 5 ) ); // Assign the "subtract" method to the static method reference. methodRef = ExampleClass.subtract; // Call the static method reference. Stream.writeLine( methodRef( 0, 5 ) ); // Declare a static method reference with a void return type. void (static)( String ) methodRefVoid = ExampleClass.message; // Call the static method reference with the void return type. methodRefVoid( "static method \"message\" called.\n" ); } // Static method to add two Integers and return a String result. private static String add( int x, int y ) { Stream.writeLine( "static method \"add\" called." ); return Integer.toString( x + y ); } } // Example class with a static subtraction method. class ExampleClass { // Static method to subtract two Integers and return a String result. public static String subtract( int x, int y ) { Stream.writeLine( "static method \"subtract\" called." ); return Integer.toString( x - y ); } public static void message( String message ) { // Output the message. Stream.write( message ); } }